package com.whw.springboot.walk.service.servicelmpl;

import com.whw.springboot.walk.entity.Message;
import com.whw.springboot.walk.entity.Reback;
import com.whw.springboot.walk.entity.RebackInfo;
import com.whw.springboot.walk.mapper.RebackInfoMapper;
import com.whw.springboot.walk.mapper.RebackMapper;
import com.whw.springboot.walk.service.RebackInfoService;
import com.whw.springboot.walk.service.RebackService;
import com.whw.springboot.walk.utils.RebackInfoUtil;
import com.whw.springboot.walk.utils.RebackUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class RebackInfoServiceImpl implements RebackInfoService {

    @Resource
    private RebackInfoMapper rebackInfoMapper;


    @Override
    public Message<?> insert(RebackInfo rebackInfo) {
        String rebackInfoId = "RN"+ RebackInfoUtil.genRebackInfoId();
        rebackInfo.setRebackInfoId(rebackInfoId);
        rebackInfo.setRebackInfoUpdateTime(new Date());
        return rebackInfoMapper.insert(rebackInfo) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> deleteByPrimaryKey(String rebackId) {
        return rebackInfoMapper.deleteByPrimaryKey(rebackId)> 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> updateByPrimaryKey(RebackInfo rebackInfo) {
        return rebackInfoMapper.updateByPrimaryKey(rebackInfo)>0 ? Message.success(null) : Message.fail(null);
    }


    @Override
    public Message<RebackInfo> findByPrimaryKey(String rebackInfoId) {
        return Message.success(null).add(rebackInfoMapper.findByPrimaryKey(rebackInfoId));
    }

    @Override
    public Message<List<RebackInfo>> findAll() {
        return Message.success(null).add(rebackInfoMapper.findAll());
    }

    @Override
    public Message<List<RebackInfo>> findRebackAndRebackInfo(String rebackRebackId) {
        return Message.success(null).add(rebackInfoMapper.findRebackAndRebackInfo2(rebackRebackId));
    }

    @Override
    public Message<?> insertBySTR(RebackInfo rebackInfo) {

        rebackInfo.setRebackInfoUpdateTime(new Date());
        return rebackInfoMapper.insert(rebackInfo) > 0 ? Message.success(null) : Message.fail(null);
    }


}
